┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system] └─$ pwd /usr/lib/systemd/system ┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system] └─$ cat sysstat.service # /usr/lib/systemd/system/sysstat.service # (C) 2012 Peter Schiffer (pschiffe <at> redhat.com) # # sysstat-10.1.5 systemd unit file: # Insert a dummy record in current daily data file. # This indicates that the counters have restarted from 0.
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system] └─$ systemctl status sysstat.service ● sysstat.service - Resets System Activity Logs Loaded: loaded (/usr/lib/systemd/system/sysstat.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2021-10-13 01:53:41 CST; 1 weeks 3 days ago Main PID: 584 (code=exited, status=0/SUCCESS) CGroup: /system.slice/sysstat.service
Oct 13 01:53:41 liruilongs.github.io systemd[1]: Starting Resets System Activity Logs... Oct 13 01:53:41 liruilongs.github.io systemd[1]: Started Resets System Activity Logs.
红帽8没有,需要自己开启,红帽7有
1 2 3 4 5
┌──[root@liruilongs.github.io]-[/] └─$ cd /var/log/sa ┌──[root@liruilongs.github.io]-[/var/log/sa] └─$ ls sa01 sa03 sa04 sa05 sa06 sa08 sa09 sa13 sa14 sa23 sa24 sa30 sar03
CPU 监控信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌──[root@liruilongs.github.io]-[/var/log/sa] └─$ sar -f sa24 -p # CPU 监控信息 Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
08:14:46 AM LINUX RESTART
08:20:03 AM CPU %user %nice %system %iowait %steal %idle 09:40:01 AM all 1.44 0.00 1.72 0.21 0.00 96.64 09:50:01 AM all 0.80 0.00 1.51 0.01 0.00 97.69 10:00:01 AM all 0.81 0.00 1.56 0.00 0.00 97.63 10:10:01 AM all 0.74 0.00 1.40 0.02 0.00 97.83 10:20:01 AM all 0.65 0.00 1.26 0.00 0.00 98.08 10:30:01 AM all 0.78 0.02 1.50 0.04 0.00 97.67 10:40:01 AM all 3.24 0.00 5.65 0.01 0.00 91.11 Average: all 1.18 0.00 2.10 0.03 0.00 96.69
负载信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌──[root@liruilongs.github.io]-[/var/log/sa] └─$ sar -f sa24 -q # 负载信息 Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
08:14:46 AM LINUX RESTART
08:20:03 AM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 09:40:01 AM 0 215 0.06 0.40 0.42 0 09:50:01 AM 0 215 0.41 0.21 0.28 0 10:00:01 AM 1 215 0.27 0.13 0.20 0 10:10:01 AM 1 216 0.03 0.08 0.14 0 10:20:01 AM 0 216 0.00 0.04 0.10 0 10:30:01 AM 1 217 0.00 0.03 0.06 0 10:40:01 AM 0 215 0.07 0.16 0.14 0 Average: 0 216 0.12 0.15 0.19 0
内存信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌──[root@liruilongs.github.io]-[/var/log/sa] └─$ sar -f sa24 -r # 内存信息 Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system] └─$ systemctl enable --now pmcd # 启动监控服务 Created symlink from /etc/systemd/system/multi-user.target.wants/pmcd.service to /usr/lib/systemd/system/pmcd.service. ┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system] └─$ systemctl enable --now pmlogger # 启动存数据的数据库 Created symlink from /etc/systemd/system/multi-user.target.wants/pmlogger.service to /usr/lib/systemd/system/pmlogger.service. ┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
┌──[root@liruilongs.github.io]-[/proc/sys/vm] └─$ cat /etc/sysc sysconfig/ sysctl.conf sysctl.d/ ┌──[root@liruilongs.github.io]-[/proc/sys/vm] └─$ cat /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward = 1 ┌──[root@liruilongs.github.io]-[/proc/sys/vm] └─$ echo"vm.swappiness = 20" >> /etc/sysctl.conf ## 永久调整 ┌──[root@liruilongs.github.io]-[/proc/sys/vm] └─$ cat /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward = 1 vm.swappiness = 20 ┌──[root@liruilongs.github.io]-[/proc/sys/vm] └─$ sysctl -p net.ipv4.ip_forward = 1 vm.swappiness = 20 ┌──[root@liruilongs.github.io]-[/proc/sys/vm] └─$
┌──[root@liruilongs.github.io]-[/etc/modprobe.d] └─$ cat /etc/security/limits.conf # /etc/security/limits.conf # #This file sets the resource limits for the users logged in via PAM. #It does not affect resource limits of the system services. # #Also note that configuration files in /etc/security/limits.d directory, #which are read in alphabetical order, override the settings in this #file in case the domain is the same or more specific. #That means for example that setting a limit for wildcard domain here #can be overriden with a wildcard setting in a config file in the #subdirectory, but a user specific setting here can be overriden only #with a user specific setting in the subdirectory. # #Each line describes a limit for a user in the form: # #<domain> <type> <item> <value> # #Where: #<domain> can be: # - a user name # - a group name, with @group syntax # - the wildcard *, for default entry # - the wildcard %, can be also used with %group syntax, # for maxlogin limit # #<type> can have the two values: # - "soft" for enforcing the soft limits # - "hard" for enforcing hard limits # #<item> can be one of the following: # - core - limits the core file size (KB) 核心文件大小 # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open file descriptors # 访问文件数量 # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # cup时间 # - nproc - max number of processes # - as - address space limit (KB) # - maxlogins - max number of logins for this user #最多的登录数 # - maxsyslogins - max number of logins on the system # - priority - the priority to run user process with # - locks - max number of file locks the user can hold # - sigpending - max number of pending signals # - msgqueue - max memory used by POSIX message queues (bytes) # - nice - max nice priority allowed to raise to values: [-20, 19] # - rtprio - max realtime priority # #<domain> <type> <item> <value> #
#* soft core 0 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #@student - maxlogins 4
# End of file
限制服务的资源之限制用户通过ssh的登录数
1 2 3
┌──[root@liruilongs.github.io]-[/etc/modprobe.d] └─$vim /etc/security/limits.conf student hard maxlogins 4
┌──[root@liruilongs.github.io]-[~] └─$ man -k systemd ┌──[root@liruilongs.github.io]-[~] └─$ man systemd.resource-control ┌──[root@liruilongs.github.io]-[~] └─$
为 systemd unit 实现资源限制
这个老师没讲,以后研究下,应该也和cgroup有关
自定义tuned调优配置集:
tuned 实现系统傻瓜化和集成化调优,操作系统预装多个调优场景配置集,这是一道RHCAS的考试题
查看调优策略
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
┌──[root@liruilongs.github.io]-[~] └─$ tuned-adm list Available profiles: - balanced - General non-specialized tuned profile - desktop - Optimize for the desktop use-case - latency-performance - Optimize for deterministic performance at the cost of increased power consumption - network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance - network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks - powersave - Optimize for low power consumption - throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads - virtual-guest - Optimize for running inside a virtual guest - virtual-host - Optimize for running KVM guests Current active profile: virtual-guest ┌──[root@liruilongs.github.io]-[~] └─$ tuned-adm recommend # 查看推荐的策略 virtual-guest ┌──[root@liruilongs.github.io]-[~] └─$ tuned-adm profile virtual-guest
[main] summary=Optimize for running inside a virtual guest include=throughput-performance
[sysctl] # If a workload mostly uses anonymous memory and it hits this limit, the entire # working set is buffered for I/O, and any more write buffering would require # swapping, so it's time to throttle writes until I/O can catch up. Workloads # that mostly use file mappings may be able to use even higher values. # # The generator of dirty data starts writeback at this percentage (system default # is 20%) vm.dirty_ratio = 30
# Filesystem I/O is usually much more efficient than swapping, so try to keep # swapping low. It's usually safe to go even lower than this on systems with # server-grade storage. vm.swappiness = 30 ┌──[root@liruilongs.github.io]-[/usr/lib/tuned/virtual-guest] └─$
┌──[root@liruilongs.github.io]-[/usr/lib/tuned/virtual-guest] └─$ yum list | grep tuned tuned.noarch 2.8.0-5.el7 @anaconda tuned.noarch 2.11.0-11.el7_9 updates tuned-gtk.noarch 2.11.0-11.el7_9 updates tuned-profiles-atomic.noarch 2.11.0-11.el7_9 updates tuned-profiles-compat.noarch 2.11.0-11.el7_9 updates tuned-profiles-cpu-partitioning.noarch 2.11.0-11.el7_9 updates tuned-profiles-mssql.noarch 2.11.0-11.el7_9 updates tuned-profiles-oracle.noarch 2.11.0-11.el7_9 updates tuned-utils.noarch 2.11.0-11.el7_9 updates tuned-utils-systemtap.noarch 2.11.0-11.el7_9 updates ┌──[root@liruilongs.github.io]-[/usr/lib/tuned/virtual-guest] └─$ yum -y install tuned-profiles-oracle.noarch .... ┌──[root@liruilongs.github.io]-[/usr/lib/tuned/virtual-guest] └─$ tuned-adm list Available profiles: - balanced - General non-specialized tuned profile - desktop - Optimize for the desktop use-case - hpc-compute - Optimize for HPC compute workloads - latency-performance - Optimize for deterministic performance at the cost of increased power consumption - network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance - network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks - oracle - Optimize for Oracle RDBMS - powersave - Optimize for low power consumption - throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads - virtual-guest - Optimize for running inside a virtual guest - virtual-host - Optimize for running KVM guests Current active profile: virtual-guest ┌──[root@liruilongs.github.io]-[/usr/lib/tuned/virtual-guest] └─$